# -*- coding: utf8 -*-

__author__ = 'Калин Павлов'

import re
import datetime


def format_bgdate_str_to_sql_str(bgdate):
	try:
		new_date = datetime.date(int(bgdate[6:]), int(bgdate[3:5]), int(bgdate[0:2]))
	except ValueError, ex:
		raise ValueError("Грешен низ за дата (%s) (%s/%s/%s)!" % (bgdate, bgdate[0:2], bgdate[6:5], bgdate[6:]))

	return new_date.strftime("%Y-%m-%d")


def format_sql_str_to_bgdate_str(sqldate):
	try:
		new_date = datetime.date(int(sqldate[0:4]), int(sqldate[5:7]), int(sqldate[8:]))
	except ValueError, ex:
		raise ValueError("Грешен низ за дата (%s) (%s/%s/%s)!" % (sqldate, sqldate[0:4], sqldate[5:7], sqldate[8:]))

	return new_date.strftime("%d.%m.%Y")

